﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JSON;
//using System.Runtime.Serialization.;
using Facebook_Graph_Toolkit.FacebookObjects;

namespace Facebook_Graph_Toolkit.GraphApi {
    /// <summary>
    /// a photo album on Facebook
    /// </summary>
    [Serializable]
    public class Album : GraphApiObject{
        internal Album(JsonObject JO) : base(JO){
            data = JO;
        }

        /// <summary>
        /// Gets the information of a photo album on Facebook
        /// </summary>
        /// <param name="AlbumID">Album ID</param>
        /// <param name="AccessToken">Access Token</param>
        public Album(string AlbumID, string AccessToken) : base(Helpers.WebResponseHelper.GetJsonFromFacebookObject(AlbumID, AccessToken)){
        }

        #region public properties
        /// <summary>The photo album ID</summary>
        public string ID {
            get {
                return (string)data["id"];
            }
        }
        /// <summary>
        /// The profile that created this album
        /// </summary>
        public NameIDPair Owner { get { return new NameIDPair((JsonObject)data["from"]); } }
        /// <summary>
        /// The title of the album
        /// </summary>
        public string Name {
            get {
                return (string)data["name"];
            }
        }
        /// <summary>
        /// The location of the album
        /// </summary>
        public string Location {
            get {
                return (string)data["location"];
            }
        }
        /// <summary>
        /// The description of the album
        /// </summary>
        public string Description {
            get {
                return (string)data["description"];
            }
        }
        /// <summary>
        /// A link to this album on Facebook
        /// </summary>
        public string NavigateUrl {
            get {
                return (string)data["link"];
            }
        }
        /// <summary>
        /// The number of photos in this album
        /// </summary>
        public int Count {
            get {
                if (data["count"] == null) return 0;
                return (int)data["count"];
            }
        }
        /// <summary>
        /// The type of the album
        /// </summary>
        public string Type {
            get {
                return (string)data["type"];
            }
        }
        /// <summary>
        /// The time the photo album was initially created
        /// </summary>
        public DateTime CreatedTime {
            get {
                return Helpers.Common.RFC3339ToDateTime((string)data["created_time"]);
            }
        }
        /// <summary>
        /// The last time the photo album was updated
        /// </summary>
        public DateTime UpdatedTime {
            get {
                return Helpers.Common.RFC3339ToDateTime((string)data["updated_time"]);
            }
        }
        #endregion

        /// <summary>
        /// Gets photos in the specified Facebook Album
        /// </summary>
        /// <param name="AlbumID">Album ID</param>
        /// <param name="AccessToken">Access Token</param>
        /// <param name="Offset">The number of photos to offset before returning the first photo</param>
        /// <param name="Limit">Maximum number of photos returned</param>
        /// <returns></returns>
        public static IList<Photo> GetPhotos(string AlbumID, string AccessToken, int? Offset, int? Limit) {
            return Helpers.ApiCaller.GetPhotos(AlbumID, AccessToken, Offset, Limit);
        }

        /// <summary>
        /// Gets the comments in the specified Facebook Album
        /// </summary>
        /// <param name="AlbumID">Album ID</param>
        /// <param name="AccessToken">Access Token</param>
        /// <param name="Offset">Number of comments to skip before returning the first comment</param>
        /// <param name="Limit">Maximum number of comments returned</param>
        /// <returns></returns>
        public static IList<Comment> GetComments(string AlbumID, string AccessToken, int? Offset, int? Limit) {
            return Helpers.ApiCaller.GetComments(AlbumID, AccessToken, Offset, Limit);
        }
    }
}
